<?php
session_start();
include "config/identitas-situs.php";
include "config/class_paging.php";
include "config/tanggalan.php";

?>

<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Halaman Administrator <?php echo $title; ?></title>
<link rel="shortcut icon" href="images/fav.ico" />
<script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
<script src="js/jquery-ui-1.10.3.custom.min.js"></script>
<link href="css/redmond/jquery-ui-1.10.3.custom.css" rel="stylesheet">
<link href="config/style.css" type="text/css" rel="stylesheet" />
</head>
<body>
 <div id="lebar-web">
	<div id="header">
		<div class="header-judul"><?php echo $namasitus; ?></div>
		<div class="header-deskripsi"><font size="4" color="44e0bd"> Halaman Administrator </font><br><br>
		<center><img src="images/smk_kebumen.jpg" height="50px"/></center>
		<b><font size="4" color="87dbf0"><marquee direction="right">
		Halaman ini hanya dapat diakses oleh admin Website Penerimaan Peserta Didik Baru (PPDB) SMK Negeri 1 Kebumen. <br></marquee>
		</font></div>
</div>
<?php
include "config/koneksi.php";

/* menge-cek admin sudah login sbg admin (username admin) atau belum */
if(isset($_SESSION[user])){
	$data = mysql_query("SELECT * FROM com_user WHERE username = '$_SESSION[user]'");
	$tampil = mysql_fetch_array($data);
?>
	 <ul id="menu_nav" class="Blue">
		<li class="button"><a href="index.php">Beranda</a></li>
		<li class="button"><a href="index.php?halaman=full-siswa">Pendaftar</a></li>
		<li class="button"><a href="index.php?halaman=urut-siswa">Pendaftar Diterima</a></li>
		<li class="button"><a href="index.php?halaman=laporan-harian">Laporan Pendaftar</a></li>
		<li class="button"><a href="index.php?halaman=daftar-proli">Daftar Proli</a></li>
       	<li class="button"><a href="ubah_password.php">Ubah Kata Sandi</a></li>
		<li class="button"><a href="logout.php">Keluar</a></li>
	 </ul>
  <div id="isi">
<?php
$hal=$_GET[halaman];
//HALAMAN DAFTAR CALON SISWA
if($hal=="full-siswa"){
?>
 <style type="text/css">
   </style>
	<H1 align="center">Semua Calon Siswa SMK Negeri 1 Kebumen</H1>
	<fieldset style="border:1px solid #0099FF">
	<legend style="font-weight:bold; color:#0066CC">
	 <a href="index.php?halaman=tambah-siswa" style="text-decoration:none">
	 
	 <a href="index.php?halaman=urut-siswa" style="text-decoration:none">
	   <button><blink>  </blink>Klik jika ingin melihat pendaftar aktif berdasarkan proli<blink>  </blink></button>
	 </a>
	</legend>
	<div style="overflow:scroll; width:980px">
	 <table id="belang">
		<tr>
			<th>No.</th>
			<th>No.Daftar</th>
			<th>Proli</th>
			<th>Nama</th>
			<th>Asal Sekolah</th>
			<th>Nilai Matematika</th>
			<th>Nilai Indonesia</th>
			<th>Nilai Inggris</th>
			<th>Nilai Ipa</th>
			<th>Jumlah</th>
			<th>Rata-rata</th>
			
			<th>Status Daftar</th>
			
			<th><img src="images/seting.png" width="18" height="18" align="center"/></th>
		</tr>
	<?php	
	$p       = new Paging;
	$batas   = 5;
	$posisi  = $p->cariPosisi($batas);
	
	$q2=mysql_query("SELECT * FROM tb_pendaftar ORDER BY no_pendaftaran ASC LIMIT $posisi,$batas");
	$no=$posisi+1;
	while($r2=mysql_fetch_array($q2)){
	
	$tgl_posting=tanggalan($r2[tanggal]);
	
	$agama=mysql_fetch_array(mysql_query("SELECT * FROM tb_agama WHERE id_agama= '$r2[id_agama]'"));
	if($r2[jk]=="1"){
	$jk ="Laki-Laki";
	}else{
	$jk="Perempuan";}
	?>
	    <tr>
	    	<td>
	    		<?php echo $no; ?>
	    	</td>
			<td>
				<?php echo $r2[no_pendaftaran]; ?>
			</td>
			 <? $proli=mysql_query("SELECT * FROM tb_proli WHERE kd_proli = '$r2[proli]'");
	$k=mysql_fetch_array($proli);?>
            <td>
				<?php echo $k[proli]; ?>
			</td>
			<td>
				<?php echo $r2[nama]; ?>
			</td>
			<td>
				<?php echo $r2[asal_sekolah]; ?>
			</td>
			<td>
            <? $nilai=mysql_query("SELECT * FROM tb_pendaftar WHERE no_pendaftaran = '$r2[no_pendaftaran]'");
		$n=mysql_fetch_array($nilai);?>
         
                <?php echo $n[matematika]; ?>
            </td>
            <td>
                <?php echo $n[indonesia]; ?>
            </td>
            <td>
                <?php echo $n[inggris]; ?>
            </td>
			<td>
                <?php echo $n[ipa]; ?>
            </td>
             <td>
                <?php 
				$jumlah=mysql_query("select matematika,indonesia,inggris, ipa ,((4*matematika)+(1*indonesia)+(3*inggris)+(2*ipa)) AS jumlah FROM tb_pendaftar WHERE no_pendaftaran = '$r2[no_pendaftaran]'");
		$j=mysql_fetch_array($jumlah); 
				echo $j[jumlah]; ?>
            </td>
			<td>
                <?php 
				$rata2=mysql_query("select matematika,indonesia,inggris, ipa ,(((4*matematika)+(1*indonesia)+(3*inggris)+(2*ipa)) div 10) AS rata2 FROM tb_pendaftar WHERE no_pendaftaran = '$r2[no_pendaftaran]'");
		$r=mysql_fetch_array($rata2); 
				echo $r[rata2]; ?>
            </td>
            
              <?php
			   if ($n['status_aktif']=='aktif'){
				$img_status="lamp-green.gif";
				$link_status="update_status.php?status=nonaktif&id=".$n['id_pendaftaran'];
			   $status="terima";}
			   else {
				$img_status="lamp-off.gif";
				$link_status="update_status.php?status=aktif&id=".$n['id_pendaftaran'];
				$status="tidak terima";}
				?>
            <td>
				<a href="<?php echo $link_status;?>"><img src="images/<?php echo $img_status;?>"></a>
			</td>
			
		
			<td>
				<a href='detailsiswa.php?id=<?php echo $r2['no_pendaftaran']; ?>' onclick='window.open(this.href,&quot;popupwindow&quot;,&quot;status=0, height=600, width=400, scrollbars=yes, resizable=0, top=10, right=0&quot;); return false;' target='_blank'>
				detail
				</a> &nbsp
			
				
				
			</td>
		</tr>
	<?php
	$no++;
	}
	?>
	</table>
	</div>
	<?php
	$jmldata=mysql_num_rows(mysql_query("SELECT * FROM tb_pendaftar"));
	$jmlhalaman = $p->jumlahHalaman($jmldata,$batas);
	$linkHalaman = $p->navHalaman($_GET[hal], $jmlhalaman);
	echo "<div class=pagination>$linkHalaman</div><br>";
	
	?>
	<br/>
  
	<?php
}


//HALAMAN TAMBAH SISWA
elseif($hal=="tambah-siswa"){
?>

<?php
}
//HALAMAN DAFTAR NILAI
elseif($hal=="nilai-siswa"){
?>
 
	
<?php
}

//HALAMAN EDIT SISWA
elseif($hal=="edit-siswa"){
	$edit=mysql_query("SELECT * FROM tb_pendaf WHERE no_pendaftaran = '$_GET[id]'");
	$e=mysql_fetch_array($edit);
?>



<?php	
}



//buat halaman proli
elseif($hal=="daftar-proli"){
?>
<h1>Daftar Program Keahlian</h1>
<table id="belang">
<tr>
	<th>No</th>
	<th>Kode</th>
	<th>Nama</th>
	<th>Kode Jurusan</th>
	<th>Kuota</th>
	<th>Aksi</th>
</tr>
<?php
$sql_proli="select * from tb_proli";
$qry_proli=mysql_query($sql_proli);
$no=1;
while($hasil_proli=mysql_fetch_array($qry_proli)){
?>
	<tr>
	<td><?php echo $no;?></td>
	<td><?php echo $hasil_proli['kd_proli'];?></td>
	<td><?php echo $hasil_proli['proli'];?></td>
	<td><?php echo $hasil_proli['kode_jurusan'];?></td>
	<td><?php echo $hasil_proli['kuota'];?></td>
	<td><a href="index.php?halaman=edit-proli&id=<?php echo $hasil_proli['kd_proli'];?>">Edit</a> | <a>Hapus</a></td>
	</tr>
<?php
$no++;
}
?>
</table>
<?php
}elseif($hal=="edit-proli"){
$id=$_GET['id'];
$sql_detail="select * from tb_proli where kd_proli='".$id."'";
$qry_detail=mysql_query($sql_detail);
$hasil_det=mysql_fetch_array($qry_detail);
?>
<form method="post" action="aksi_proli.php?jenis=update">
<table id="belang">
<tr>
	<th>Kode Proli</th>
	<th><input type="hidden" name="kode" value="<?php echo $hasil_det['kd_proli'];?>"/><?php echo $hasil_det['kd_proli'];?></th>
</tr>
<tr>
	<th>Nama Proli</th>
	<th><input type="text" name="nama" value="<?php echo $hasil_det['proli'];?>" size="30"/></th>
</tr>
<tr>
	<th>Kode Urut</th>
	<th><input type="text" name="kode_urut" value="<?php echo $hasil_det['kode_jurusan'];?>" size="5"/></th>
</tr>
<tr>
	<th>Kuota</th>
	<th><input type="text" name="kuota" value="<?php echo $hasil_det['kuota'];?>" size="5"/></th>
</tr>
<tr>
 	<td colspan="2" align="right">
		<input type="submit" id="sub" name="sub" value="Ubah" />	</td>
 </tr>
</table>
</form>
<?php
//akhir proli
}elseif($hal=="laporan-harian"){
?>
 <script type="text/javascript">
 $(document).ready(function(){
	$("#tanggal").datepicker({
		dateFormat: 'yy-mm-dd'
	});
});
 </script>
 <H1 align="center">Laporan Pendaftaran Harian</H1>
<form method="post" action="laporan_harian.php" target="_blank">
<table id="belang">
<tr>
	<th>Tanggal</th>
	<th><input type="text" id="tanggal" name="tanggal" value="<?php echo date('Y-m-d');?>"/></th>
</tr>
<tr>
	<th>Proli</th>
	<th><select name="proli" id="proli">
	   <option value="semua">Semua</option>
    <?php

$q=mysql_query("select * from tb_proli");
 while($r=mysql_fetch_array($q)){

 if($r['kd_proli'] == $e['proli']){
 echo "<option value=$r[kd_proli] selected>$r[proli]</option>";
 }else{
 echo "<option value=$r[kd_proli]>$r[proli]</option>";
 }
 }
   ?>
   </select></th>
</tr>
<tr>
 	<td colspan="2" align="right">
		<input type="submit" id="sub" name="sub" value="Tampilkan" />	</td>
 </tr>
</table>
</form>
<?php
}elseif($hal=="urut-siswa"){

?>
 <style type="text/css">
   </style>
 <form action="index.php?halaman=urut-siswa" method="post">
 <b>Tampilkan Berdasarkan : </b> 
  * Proli &nbsp;<select name="proli">
  <?php
  $proli=mysql_query("SELECT * FROM tb_proli");
  while($upro=mysql_fetch_array($proli)){
   echo "<option value='$upro[kd_proli]'>$upro[proli]</option>";
  }
  ?>
 </select>
  <input type="submit" name="urutkan" value="Tampilkan" />
</form>
	<?php
	
	
	
	?>
	<br />
	<?php
if(isset($_POST['urutkan'])){
?>
	<fieldset style="border:1px solid #0099FF">
	<legend style="font-weight:bold; color:#0066CC">
	Nama Pendaftar : 
	</legend><div style="overflow:scroll; width:980px">
    <?
    $tgl_posting=tanggalan($r3[tanggal]);
	$proli=$_POST['proli'];
	$vkelas=mysql_fetch_array(mysql_query("select * from tb_proli where kd_proli='$_POST[proli]'"));
	$sql_sert="select count(*) as jumlah from tb_pendaftar where proli='".$_POST['proli']."' and status_terima_sertifikat='diterima'";
	//echo $sql_sert;
	$qry_sert=mysql_query($sql_sert);
	$hasil_sert=mysql_fetch_array($qry_sert);
	$jml_terima_sert=$hasil_sert['jumlah'];
	$kuota=$vkelas['kuota']-$jml_terima_sert;
	$cadangan=$kuota+2;
	//echo 'kuota '.$kuota;
	$sql_urut="SELECT * FROM (
			SELECT no_pendaftaran,id_pendaftaran,nama,matematika,indonesia,inggris, ipa ,asal_sekolah,
			 (
      (4 * matematika) + (1 * indonesia) + (3 * inggris) + (2 * ipa) + (
       IFNULL((
          SELECT 
            SUM(nilai) 
          FROM
            tb_sertifikat 
          WHERE id_pendaftar = a.id_pendaftaran
          ),0)
      )
    ) AS jumlah ,
    (
       IFNULL((
          SELECT 
            SUM(nilai) 
          FROM
            tb_sertifikat 
          WHERE id_pendaftar = a.id_pendaftaran
          ),0)
      )AS nilai_sert
			FROM tb_pendaftar a
			WHERE proli='".$proli."' and status_aktif='aktif' and status_terima_sertifikat <> 'diterima') AS data_raw 
			ORDER BY jumlah DESC,matematika  DESC ";
			//echo $sql_urut;
			$q3=mysql_query($sql_urut);
				/*
				$q3=mysql_query("
				SELECT
tb_pendaftar.matematika+tb_pendaftar.indonesia+tb_pendaftar.+tb_pendaftar.ipa AS JUM,
tb_pendaftar.no_pendaftaran,
tb_proli.proli,
tb_pendaftar.nama,
tb_pendaftar.matematika,
tb_pendaftar.indonesia,
tb_pendaftar.inggris,
tb_pendaftar.ipa,
tb_nilai.`status`,



FROM
tb_nilai
Inner Join tb_pendaftar ON tb_pendaftar.no_pendaftaran = tb_nilai.no_pendaftaran
Inner Join tb_proli ON tb_proli.kd_proli = tb_pendaftar.proli
Where tb_proli.kd_proli='$_POST[proli]'
ORDER BY
JUM DESC");
*/
?>

	<table id="belang">
		<tr>
			<th>No</th>
			<th>No Pendaftaran</th>
			<th>Nama</th>
			<th>Asal Sekolah</th>
			<th>Nilai Matematika</th>
			<th>Nilai Bhs.Indonesia</th>
			<th>Nilai Bhs.Inggris</th>
			<th>Nilai IPA</th>
			<th>Nilai Sertifikat</th>
			<th>Jumlah</th>
			<th>Rata-rata</th>
			<th>Status</th>
		</tr>
	<?php	
	/* menampilkan semua siswa  */
	$no=1;
	while($r3=mysql_fetch_array($q3)){
		  $proli=mysql_query("SELECT * FROM tb_proli WHERE kd_proli = '$r3[proli]'");
	$k=mysql_fetch_array($proli);
				
				if($r3[jk]=="1")
				{
					$jk ="Laki-Laki";
				}
				else
				{
					$jk="Perempuan";
				}
				/*
				if ($r3[status]=='1')
			   
			   {
			   $status="terima";}
			   else {
				$status="tidak terima";}
				*/
				if($no <=$kuota){
					$status='diterima';
				}elseif($no <=$cadangan){
					$status="cadangan";
				}else{
					$status='tidak_diterima';
				}
				$sql_update="update tb_pendaftar set status_terima='".$status."' where id_pendaftaran='".$r3['id_pendaftaran']."'";
				$qry_update=mysql_query($sql_update);
	
				$rata=round($r3['jumlah']/10,2);
	
				?>
<tr>
					<td><?php echo $no; ?></td>
					<td><?php echo $r3['no_pendaftaran']; ?></td>
					<td><?php echo $r3[nama]; ?></td>
	                <td><?php echo $r3['asal_sekolah']; ?></td>
            		<td><?php echo $r3[matematika]; ?></td>
					<td><?php echo $r3[indonesia]; ?></td>
                    <td><?php echo $r3[inggris]; ?></td>
					<td><?php echo $r3[ipa]; ?></td>
					<td><?php echo $r3['nilai_sert']; ?></td>
         <td>
         <?php echo $r3['jumlah']; ?>
         </td>
                   
             
              <?php
			   
				?>
				 <td>
				   <?php echo $rata; ?> 
				   	
                
                   </td>
                   <td>
				   <?php 
				   $arr_status=array('diterima'=>'Diterima','cadangan'=>'Cadangan','tidak_diterima'=>'Tidak Diterima');
				   echo $arr_status[$status]; ?> 
				   	
                
                   </td>
				   
				   
				   </tr>
                   <?
					$no++;
	}	
	$k=$_POST[jurusan];
	?>
			
		</table>
		</div>
        <br/>
  
		</fieldset>
	<fieldset style="border:1px solid #0099FF">
	<legend style="font-weight:bold; color:#0066CC">
	Pendaftar Lulus Sertifikat: 
	</legend><div style="width:780px">
	<table id="belang">
		<tr>
			<th>No</th>
			<th>No Pendaftaran</th>
			<th>Nama</th>
			<th>Asal Sekolah</th>
		</tr>
	<?php
	$sql_sert="select * from tb_pendaftar where proli='".$_POST['proli']."' and status_terima_sertifikat='diterima'";
	//echo $sql_sert;
	$qry_sert=mysql_query($sql_sert);
	$no_sert=1;
	while($hasil_sert=mysql_fetch_array($qry_sert)){
	?>
	<tr>
		<td><?php echo $no_sert;?></td>
		<td><?php echo $hasil_sert['no_pendaftaran']?></td>
		<td><?php echo $hasil_sert['nama']?></td>
		<td><?php echo $hasil_sert['asal_sekolah']?></td>
	</tr>
	<?php
		$no_sert++;
	}
	?>
	</table>
	
	</div>
</fieldset>
		<?php
		}
		?>
		</table>
<?php
}
else {
//homepage admin
?>
        <center>
<img src="images/user.jpg" />
<H2>ANDA MASUK SEBAGAI <?php echo $_SESSION["user"]; ?></H2>
<b>Silakan Gunakan Menu di atas untuk Mengatur Web Anda</b>
</center>
<?php
}

//TAMPILAN JIKA BELUM LOGIN
} else {
?>
	 <ul id="menu_nav" class="Blue">
		<li class="button"><b><marquee bgcolor="38f8d6" style="font-family: Arial; font-size:20px; color:#800C0C;">
 <H1 align="center">Selamat datang di Halaman Administrator Website Penerimaan Peserta Didik Baru SMK Negeri 1 Kebumen</H1></marquee></b></li>
	 </ul>
  <div id="isi">
   <center><img src="images/login.jpg" /></center>
<?php
 include "login.php";
}
?>
</div>
 	<div style="clear:both" />
 	<div id="footer" align="center"><?php echo $namasitus; ?> <br><br>&copy; 2014. Copyrigt by: <a href="author.php">Lulu Infajaroh</a>
	<a href="#header" title="Kembali ke Atas"><img src="images/go-top.png" style="float:right; width:15px; height:15px;" /></a></div>
 </div>
	</body>
    </html>
